-- @owner: @li-xin12345
-- @date: 2022/08/05
-- @testpoint: 多表测试distinct + 主键(不消除distinct)走sort distinct

--step1：创建测试表; expect:成功
drop table if exists t_ustore_sortdistinct_011_01;
create table t_ustore_sortdistinct_011_01(
     col_1 integer,
     col_2 bigint constraint t_ustore_sortdistinct_011_01_pk primary key,
     col_3 float8,
     col_4 decimal(12,6),
     col_5 bool,
     col_6 char(30),
     col_7 varchar2(50),
     col_8 varchar(30),
     col_9 interval day to second,
     col_10 timestamp,
     col_11 date,
     col_12 smalldatetime,
     col_13 timestamp without time zone,
     col_14 blob,
     col_15 clob,
     col_16 int[]
) with (storage_type=ustore);
drop table if exists t_ustore_sortdistinct_011_02;
create table t_ustore_sortdistinct_011_02(idllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll int,
啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦l int,name varchar(20),sal int,col_16 int[],b_boolean boolean,
f_floor decimal(10,2)) with (storage_type=ustore);

--step2：创建序列并插入数据；except：成功
drop sequence if exists seq_ustore_sortdistinct;
create sequence seq_ustore_sortdistinct increment by 1 start with 10;
insert into t_ustore_sortdistinct_011_01 values(1,seq_ustore_sortdistinct.nextval,   1+445.255,98*0.99,
true,lpad('abc','6','@'),lpad('abc','5','b'),rpad('abc','6','e'),(interval '4 5:12:10.222' day to second(3)),
to_timestamp('2019-01-03 14:58:54.000000','yyyy-mm-dd hh24:mi:ss.ffffff'), to_timestamp('2019-01-03 14:58:54.000000',
'yyyy-mm-dd hh24:mi:ss.ffffff'),to_timestamp('2019-01-03 14:58:54.000000','yyyy-mm-dd hh24:mi:ss.ffffff'),
to_timestamp('2019-01-03 14:58:54.000000','yyyy-mm-dd hh24:mi:ss.ffffff'),   lpad('10','12','01010')::blob,
rpad('abc','9','a@123&^%djgk'),'{32,535,5645645,6767,76,67,56,48,979,978,7}');
insert into t_ustore_sortdistinct_011_01 values(1,seq_ustore_sortdistinct.nextval, 1+445.255,98*0.99,
true,lpad('abc','6','@'),lpad('abc','6','b'),rpad('abc','5','e'),(interval '4 5:12:10.222' day to second(3)),
to_timestamp('2019-01-03 14:58:54.000000','yyyy-mm-dd hh24:mi:ss.ffffff'),  to_timestamp('2019-01-03 14:58:54.000000',
'yyyy-mm-dd hh24:mi:ss.ffffff'),to_timestamp('2019-01-03 14:58:54.000000','yyyy-mm-dd hh24:mi:ss.ffffff'),
to_timestamp('2019-01-03 14:58:54.000000','yyyy-mm-dd hh24:mi:ss.ffffff'),    lpad('10','12','01010')::blob,
rpad('abc','9','a@123&^%djgk'),'{32,535,5645645,6767,76,67,56,48,979,978,7}');
insert into t_ustore_sortdistinct_011_01 values(2,seq_ustore_sortdistinct.nextval,   1+445.255,98*0.99,
false,lpad('abc','6','@'),lpad('abc','5','b'),rpad('abc','5','e'),(interval '4 5:12:10.222' day to second(3)),
to_timestamp('2019-01-03 14:58:54.000000','yyyy-mm-dd hh24:mi:ss.ffffff'),to_timestamp('2019-01-03 14:58:54.000000',
'yyyy-mm-dd hh24:mi:ss.ffffff'),to_timestamp('2019-01-03 14:58:54.000000','yyyy-mm-dd hh24:mi:ss.ffffff'),
to_timestamp('2019-01-03 14:58:54.000000','yyyy-mm-dd hh24:mi:ss.ffffff'),    lpad('10','12','01010')::blob,
rpad('abc','9','a@123&^%djgk'),'{43,535,5645645,6767,76,67,56,48,979,978,7}');
insert into t_ustore_sortdistinct_011_01 values(3,seq_ustore_sortdistinct.nextval,   1+445.255,98*0.99,
false,lpad('abc','4','@'),lpad('abc','4','b'),rpad('abc','6','e'),(interval '4 5:12:10.222' day to second(3)),
to_timestamp('2019-01-03 14:58:54.000000','yyyy-mm-dd hh24:mi:ss.ffffff'),  to_timestamp('2019-01-03 14:58:54.000000',
'yyyy-mm-dd hh24:mi:ss.ffffff'),to_timestamp('2019-01-03 14:58:54.000000','yyyy-mm-dd hh24:mi:ss.ffffff'),
to_timestamp('2019-01-03 14:58:54.000000','yyyy-mm-dd hh24:mi:ss.ffffff'),  lpad('10','12','01010')::blob,
rpad('abc','9','a@123&^%djgk'),'{32,535,5645645,6767,76,67,56,48,979,978,7}');
insert into t_ustore_sortdistinct_011_01 values(3,seq_ustore_sortdistinct.nextval,   1+445.255,98*0.99,
false,lpad('abc','3','@'),lpad('abc','3','b'),rpad('abc','3','e'),(interval '4 5:07:10.222' day to second(3)),
to_timestamp('2019-01-03 14:58:54.000000','yyyy-mm-dd hh24:mi:ss.ffffff'),  to_timestamp('2019-01-03 14:58:54.000000',
'yyyy-mm-dd hh24:mi:ss.ffffff'),to_timestamp('2019-01-03 14:58:54.000000','yyyy-mm-dd hh24:mi:ss.ffffff'),
to_timestamp('2019-01-03 14:58:54.000000','yyyy-mm-dd hh24:mi:ss.ffffff'),  lpad('10','12','01010')::blob,
rpad('abc','9','a@123&^%djgk'),'{32,535,5645645,6767,76,67,56,48,979,978,7}');
insert into t_ustore_sortdistinct_011_01 values(4,seq_ustore_sortdistinct.nextval,   1+445.255,98*0.99,
true,lpad('abc','3','@'),lpad('abc','4','b'),rpad('abc','6','e'),(interval '4 5:07:10.222' day to second(3)),
to_timestamp('2019-01-03 14:58:54.000000','yyyy-mm-dd hh24:mi:ss.ffffff'),  to_timestamp('2019-01-03 14:58:54.000000',
'yyyy-mm-dd hh24:mi:ss.ffffff'),to_timestamp('2019-01-03 14:58:54.000000','yyyy-mm-dd hh24:mi:ss.ffffff'),
to_timestamp('2019-01-03 14:58:54.000000','yyyy-mm-dd hh24:mi:ss.ffffff'),  lpad('10','12','01010')::blob,
rpad('abc','9','a@123&^%djgk'),'{43,535,5645645,6767,76,67,56,48,979,978,7}');
insert into t_ustore_sortdistinct_011_02 values(1,1,'1aa',120,'{1,2,3}',true,10.2);
insert into t_ustore_sortdistinct_011_02 values(2,1,'2aa',300,'{1,3,3}',false,100.2);
insert into t_ustore_sortdistinct_011_02 values(3,1,'3aa',100,'{1,2,3}',true,99.2);
insert into t_ustore_sortdistinct_011_02 values(4,1,'4aa',99,'{1,2,3}',true,67.2);
insert into t_ustore_sortdistinct_011_02 values(5,1,'5aa',90,'{1,3,3}',false,67.2);
insert into t_ustore_sortdistinct_011_02 values(6,2,'6aa',87,'{1,2,3}',true,10.2);
insert into t_ustore_sortdistinct_011_02 values(7,2,'7aa',500,'{1,2,3}',false,99.2);
insert into t_ustore_sortdistinct_011_02 values(8,2,'8aa',200,'{2,3,3}',true,10.2);
insert into t_ustore_sortdistinct_011_02 values(9,2,'9aa',20,'{1,3,3}',false,99.5);
insert into t_ustore_sortdistinct_011_02 values(10,2,'10aa',30,'{2,3,3}',true,99.5);
insert into t_ustore_sortdistinct_011_02 values(null,2,'10aa',30,'{2,3,3}',false,10.2);
insert into t_ustore_sortdistinct_011_02 values(12,2,'10aa',null,'{2,3,3}',true,10.2);

--step3：多表测试distinct + 主键(不消除distinct)走sort distinct；except：成功
select distinct t1.col_2 from t_ustore_sortdistinct_011_01 t1 inner join t_ustore_sortdistinct_011_02 t2
on t1.col_1=t2.idllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll order by 1;
explain plan for select distinct t1.col_2 from t_ustore_sortdistinct_011_01 t1 inner join t_ustore_sortdistinct_011_02 t2
on t1.col_1=t2.idllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll order by 1;

--step4：清理环境；except：成功
delete from plan_table;
drop sequence seq_ustore_sortdistinct;
drop table t_ustore_sortdistinct_011_01;
drop table t_ustore_sortdistinct_011_02;